package 网络编程.Text;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPText4 {
    public static void main(String[] args) throws IOException {
        //客户端:发送一条数据,接收服务端反馈的信息,打印
        //服务器:接收数据并打印,在给客户端反馈信息
        ServerSocket ss=new ServerSocket(10005);
        //监控客户端连接
        Socket accept = ss.accept();
        InputStreamReader isr=new InputStreamReader(accept.getInputStream());
        int a;
        /*细节:
        * read方法是从通道中读取数据
        * 但是要有结束标记,此才会从通道里跳出
        * 否则程序会一直留到通道中*/
        while ((a=isr.read())!=-1){
            System.out.println((char) a);
        }
        //给客户端反馈信息
        OutputStream outputStream = accept.getOutputStream();
        String s="接收成功";
        outputStream.write(s.getBytes());
        //释放资源
        outputStream.close();
        accept.close();
        ss.close();
    }
}
